//    Copyright (C) Kherty.  All rights reserved.
using System.Collections.Generic;
using System.Diagnostics;

namespace OpenLS.Spreadsheet
{
    abstract class RangeNodeBase: IDependencyNode, IWeakable
    {
        #region IDependencyNode Members

        public IEnumerable<IDependencyNode> Dependents()
        {
            foreach (IDependencyNode node in _dependents)
                yield return node;
        }

        readonly HashListNoDuplicate<IDependencyNode> _dependents = new HashListNoDuplicate<IDependencyNode>();

        public bool ProcessChange()
        {
            Debug.WriteLine("No Process Change for " + this);
            return false;
        }

        public void ChainRecalc()
        {

        }

        public void AddDependent(IDependencyNode node)
        {
#if DEBUG
           // Contract.Assert(ValidToAdd (node));
#endif
             _dependents.Add(node);
        }
        #if DEBUG
        protected virtual bool ValidToAdd(IDependencyNode node)
        {
            return true;
        }
#endif

        public void RemoveDependent(IDependencyNode node)
        {
            _dependents.Remove(node);
        }

        #endregion

        #region IWeakable Members

        object IWeakable.WeakHolder { get; set; }

        #endregion
    }
}
